#coding=utf-8
from uliweb.form import *
from uliweb.i18n import ugettext_lazy as _

class RiskpointForm(Form):
    def form_validate(self, data):
        from uliweb.orm import get_model
        error = {}
#        task_dev = get_model('tasks_develop')
#        task_flag = task_dev.get(task_dev.c.id == data['task_id'])
#        if not task_flag:
#            data['task_id'] = None
#        else:
#            
#        if data['task_id']:
#            
#            sys = task_dev.get(task_dev.c.id == data['task_id'])
#            if not sys:
#                error['task_id'] = '任务编号填写有误或未填写！'
#        if data['task_id'] != None and data['solution_mode'] != '1':
#            error['solution_mode'] = '有关联任务，解决方式不是开发任务方式解决！'
        return error

class RisksolutionForm(Form):
    def form_validate(self, data):
        from uliweb.orm import get_model
        task_dev = get_model('tasks_develop')
        error = {}
        if data['solution_mode'] == '2' and data['nondev_riskpoint_status']=='F':
            if not data['finish_date']:
                error['finish_date'] = '整改措施状态为完成时，必须填写实际完成时间！'
            if not data['result']:
                error['result'] = '整改措施解决方式为开发任务方式，状态为完成时，必须填写整改效果！'
            
        if data['solution_mode'] == '1':
            if data['task_id']:
                task_flag = task_dev.get(task_dev.c.id == data['task_id'])
                if task_flag and task_flag.stage == 'FN' and not data['itsm_num']:
                    error['itsm_num'] = '整改措施解决方式为开发任务方式，状态为完成时，必须填写ITSM单号！'
                if task_flag and task_flag.stage == 'FN' and not data['result']:
                    error['result'] = '整改措施解决方式为开发任务方式，状态为完成时，必须填写整改效果！'
                
        return error
